<template>
  <div class="wrap">
    <el-card class="box-card" style="height: 500px">
      <el-form ref="form" :model="form" label-width="120px">

        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-radio-group v-model="form.sex">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="问题描述" prop="question">
          <el-input v-model="form.question" type="textarea"></el-input>
        </el-form-item>
        <el-form-item label="主要症状" prop="symptom">
          <el-input v-model="form.symptom" type="textarea"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即咨询</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  export default {
    name : "consult" ,
    data () {
      return {
        form : {
          question : '' ,
          symptom : '' ,
          age : '' ,
          sex : '' ,
          name : ''
        },
        userName:'',
        userId:''
      }
    } ,
    created () {
      this.form.teacherId = this.$route.query.id
      this.getUserInfo()
    },
    methods : {
      onSubmit () {
        this.$axios ( {
          url : '/api/addConsult' ,
          method : 'post' ,
          data : {
            ... this.form
          }
        } ).then ( res => {
          if ( res.data.code == 200 ) {
            this.$message ( {
              message : '咨询成功' ,
              type : 'success'
            } )
            this.$router.push ( { path : '/startExam' } )
          }
        } )
      },
      getUserInfo() { //获取用户信息
        this.userName = this.$cookies.get("cname")
        this.form.userId = this.$cookies.get("cid")
      },

      cancel(){
        this.$refs.form.resetFields();
      }
    }
  }
</script>

<style scoped>
  .wrap {
    width: 85%;
    margin: 30px auto;
    height: 100%;
  }
</style>
